﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Jarvis.Sensors
{
    class DriveSensor : Sensor
    {
        public DriveSensor()
            : base(1000)
        {
            this.name = "Drive Sensor";
        }

        public override void Sense(Object stateInfo)
        {
            List<DriveInfo> foundDrives = new List<DriveInfo>();

            String[] letters = new String[] {"C", "D", "E", "F", "G", "H", "I",
                                             "J", "K", "L", "M", "N", "O", "P", 
                                             "Q", "R", "S", "T", "U", "V", "W",
                                             "X", "Y", "Z"};

            foreach (String letter in letters)
            {
                try
                {
                    DriveInfo d = new DriveInfo(letter);

                    foundDrives.Add(d);
                }
                catch (Exception)
                {

                }
            }

            // Below commented out as it polls floppy drives as well.
            // DriveInfo[] drives = DriveInfo.GetDrives();

            List<Object> drive_list = new List<Object>();

            foreach (DriveInfo drive in foundDrives)
            {
                if (drive.IsReady)
                {
                    string drive_desc = drive.Name;

                    if (drive.VolumeLabel != null)
                        drive_desc = drive.VolumeLabel + " (" + drive.Name + ")";

                    drive_list.Add(drive_desc);
                }
            }

            this.log(drive_list);
        }
    }
}
